package net.fei.scan.quick.db

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper

class DatabaseHelper(context: Context) : SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) {

    companion object {
        const val DATABASE_NAME = "my_data_table"
        const val DATABASE_VERSION = 1

        const val TABLE_NAME = "my_table"
        const val COLUMN_ID = "id"
        const val COLUMN_TITLE = "title"
        const val COLUMN_CONTENT = "content"
        const val COLUMN_CURRENT_TIME = "currentTime"
        const val COLUMN_TYPE = "type"
        const val IMAGE = "image"
        const val STATUS = "status"
    }

    private val CREATE_TABLE = "CREATE TABLE $TABLE_NAME (" +
            "$COLUMN_ID INTEGER PRIMARY KEY AUTOINCREMENT," +
            "$COLUMN_TITLE TEXT," +
            "$COLUMN_CONTENT TEXT," +
            "$COLUMN_CURRENT_TIME TEXT," +
            "$COLUMN_TYPE TEXT," +
            "$IMAGE INT," +
            "$STATUS INT);"


    override fun onCreate(db: SQLiteDatabase) {
        db.execSQL(CREATE_TABLE)
    }

    override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
        db.execSQL("DROP TABLE IF EXISTS $TABLE_NAME")
        onCreate(db)
    }
}
